﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WiTeach.ClassManagement.Other;
using WiTeach.Tools;
using System.Diagnostics;
using WiTeach.ClassManagement.DAL;
using WiTeach.MaterialManagement.View;
using WiTeach.ClassManagement.Model;
using MoonPdfLib;

namespace WiTeach.CourseManagement.View
{
    /// <summary>
    /// temp.xaml 的交互逻辑
    /// </summary>
    public partial class ClassStudyIndex : Page
    {
        public string class_name;
        public int classHourID;
        public int lessonID;


        public ClassStudyIndex()
        {
            InitializeComponent();
            // 修改页面背景主题
            ImageBrush brush = new ImageBrush();
            brush.Stretch = Stretch.Fill;
            brush.ImageSource = new BitmapImage(new Uri("background\\default.jpg", UriKind.Relative));
            this.Background = brush;
        }


        public ClassStudyIndex(int classHour_ID, string className, int lessonID)
        {
            InitializeComponent();
            // 修改页面背景主题
            ImageBrush brush = new ImageBrush();
            brush.Stretch = Stretch.Fill;
            brush.ImageSource = new BitmapImage(new Uri(App.backgroundImage, UriKind.RelativeOrAbsolute));
            this.Background = brush;
            //this.Height = SystemParameters.PrimaryScreenHeight;
            //this.Width = SystemParameters.PrimaryScreenWidth;
            class_name = className;
            this.studyPageTitle.Content = className + "——学一学";
            this.classHourID = classHour_ID;
            this.lessonID = lessonID;

        }

        public string getClassName()
        {
            return class_name;
        }

        private void backHomeButton_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.GetNavigationService(this).Navigate(new Uri("/WiTeach;component/CourseManagement/View/CourseIndex.xaml", UriKind.Relative));
        }

        private void backPreLevel(object sender, RoutedEventArgs e)
        {
            this.NavigationService.GoBack();
            //NavigationService.GetNavigationService(this).Navigate(new Uri("/WiTeach;component/ClassManagement/View/ClassIndex.xaml", UriKind.Relative));
        }

        private void experimentMaterialButton(object sender, RoutedEventArgs e)
        {
            NavigationService.GetNavigationService(this).Navigate(new Uri("/WiTeach;component/MaterialManagement/View/materialShow.xaml", UriKind.Relative));
        }

        private void PlayPresentation(object sender, RoutedEventArgs e)
        {
            // 播放演示文稿
            //FileHelper fileHelper = new FileHelper();
            //string pptName = FileDAL.getPPTUrlByClassHourID(classHourID);
            //string pptFullPath = fileHelper.GetExecutionDirectoryFileFullPath("ppt\\", pptName);
            //Console.WriteLine("pptfullpath" + pptFullPath);
            //string fileFullPath = fileHelper.GetFinderFileFullPath("\\Resource\\file\\", "testppt.pptx");

            //*********************************************************************************** 
            /* 组件方式调用打开Ppt
           MainWindow window =  (MainWindow)Window.GetWindow(this);
           window.Topmost = false;
            List<ClassHour> list = ClassHourDAL.getClassListByID(this.lessonID, this.classHourID);
            string pptFullPath = list[0].PPTName.ToString();
            
            OpenPresentation presentation = new OpenPresentation();
            presentation.Open(pptFullPath);
            GC.Collect();
            */
            //*********************************************************************************** 

            // 通过调用进程方式打开
            List<ClassHour> list = ClassHourDAL.getClassListByID(this.lessonID, this.classHourID);
            string pptPath = list[0].PPTName.ToString();
            Process process = new Process();
            try
            {
                process.StartInfo.FileName = pptPath;
                process.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
                process.Start();
                process.WaitForExit();
                process.Close();
                GC.Collect();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                process.Close();
                GC.Collect();
            }

        }

        private void material(object sender, RoutedEventArgs e)
        {
            MaterialList materialList = new MaterialList(classHourID, lessonID);
            this.NavigationService.Navigate(materialList);

        }

        private void pdfOpen(object sender, RoutedEventArgs e)
        {
            //string pdf_reader = System.Configuration.ConfigurationManager.AppSettings["pdf_reader"];
            //try
            //{
            //    System.Diagnostics.Process.Start(@pdf_reader);
            //}
            //catch (Exception)
            //{
            //}
            //NavigationService.GetNavigationService(this).Navigate(new Uri("/WiTeach;component/pdfReader.xaml", UriKind.Relative));
            //pdfReader mPdfReader = new pdfReader(classHourID, lessonID);
            //this.NavigationService.Navigate(mPdfReader);

           

            List<ClassHour> list = ClassHourDAL.getClassListByID(this.lessonID, this.classHourID);
            string pdfPath = list[0].PDFName.ToString();
            Process process = new Process();
            try
            {
                process.StartInfo.FileName = pdfPath;
                process.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
                process.Start();
                process.WaitForExit();
                process.Close();
                GC.Collect();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                process.Close();
                GC.Collect();
            }

        }


        private void classstudy_backmain_mouse_enter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 66;
            image.Width = 104;
        }
        private void classstudy_backmain_mouse_leave(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 60;
            image.Width = 98;
        }
        private void classstudy_back_mouse_enter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 66;
            image.Width = 104;
        }
        private void classstudy_back_mouse_leave(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 60;
            image.Width = 98;
        }

        private void classstudy_choice_mouse_enter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 250;
            image.Width = 256;
        }
        private void classstudy_choice_mouse_leave(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 244;
            image.Width = 250;
        }

        private void classstudy_keil_mouse_enter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 56;
            image.Width = 59;
        }
        private void classstudy_keil_mouse_leave(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 46;
            image.Width = 49;
        }
        private void classstudy_arduino_mouse_enter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 54;
            image.Width = 60;
        }
        private void classstudy_arduino_mouse_leave(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 48;
            image.Width = 54;
        }
        private void classstudy_flymcu_mouse_enter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 52;
            image.Width = 60;
        }
        private void classstudy_flymcu_mouse_leave(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 48;
            image.Width = 54;
        }
        private void classstudy_progisp_mouse_enter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 52;
            image.Width = 59;
        }
        private void classstudy_progisp_mouse_leave(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 48;
            image.Width = 54;
        }
        private void classstudy_s4a_mouse_enter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 53;
            image.Width = 59;
        }
        private void classstudy_s4a_mouse_leave(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 48;
            image.Width = 54;
        }
        private void uv4_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string KEIL_Lic_path = System.Configuration.ConfigurationManager.AppSettings["app_KEIL_Lic"];
                Process uv4 = new Process();
                uv4.StartInfo.FileName = KEIL_Lic_path;
                uv4.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
                uv4.Start();
                uv4.WaitForExit();
                uv4.Close();
            }
            catch (Exception)
            {
            }

            //   System.Diagnostics.Process.Start(@KEIL_Lic_path);
        }

        private void progisp_Click(object sender, RoutedEventArgs e)
        {
            string progisp_path = System.Configuration.ConfigurationManager.AppSettings["app_progisp"];


            //     System.Diagnostics.Process.Start(@progisp_path);
            try
            {
                Process progisp = new Process();
                progisp.StartInfo.FileName = progisp_path;
                progisp.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
                progisp.Start();
                progisp.WaitForExit();
                progisp.Close();
                GC.Collect();
            }
            catch (Exception)
            {
            }

        }

        private void flymcu_Click(object sender, RoutedEventArgs e)
        {
            string flymcu_path = System.Configuration.ConfigurationManager.AppSettings["app_flymcu"];
            //          System.Diagnostics.Process.Start(@flymcu_path);
            try
            {
                Process flymcu = new Process();
                flymcu.StartInfo.FileName = flymcu_path;
                flymcu.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
                flymcu.Start();
                flymcu.WaitForExit();
                flymcu.Close();
                GC.Collect();
            }
            catch (Exception)
            {
            }

        }

        private void arduino_Click(object sender, RoutedEventArgs e)
        {
            string arduino_path = System.Configuration.ConfigurationManager.AppSettings["app_arduino"];
            //        System.Diagnostics.Process.Start(@arduino_path);
            try
            {
                Process arduino = new Process();
                arduino.StartInfo.FileName = arduino_path;
                arduino.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
                arduino.Start();
                arduino.WaitForExit();
                arduino.Close();
                GC.Collect();
            }
            catch (Exception)
            {
            }

        }
        private void scratch_Click(object sender, RoutedEventArgs e)
        {
            string scratch_path = System.Configuration.ConfigurationManager.AppSettings["app_scratch"];
            //        System.Diagnostics.Process.Start(@arduino_path);
            try
            {
                Process scratch = new Process();
                scratch.StartInfo.FileName = scratch_path;
                scratch.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
                scratch.Start();
                scratch.WaitForExit();
                scratch.Close();
                GC.Collect();
            }
            catch (Exception)
            {
            }

        }

        private void anaconda_Click(object sender, RoutedEventArgs e)
        {
            string anaconda_path = System.Configuration.ConfigurationManager.AppSettings["app_anaconda"];
            //        System.Diagnostics.Process.Start(@arduino_path);
            try
            {
                Process scratch = new Process();
                scratch.StartInfo.FileName = anaconda_path;
                scratch.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
                scratch.Start();
                scratch.WaitForExit();
                scratch.Close();
                GC.Collect();
            }
            catch (Exception)
            {
            }

        }
        private void course_scratch_mouse_enter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 54;
            image.Width = 60;
        }
        private void course_scratch_mouse_leave(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 48;
            image.Width = 54;
        }

        private void sa_Click(object sender, RoutedEventArgs e)
        {
            string sa_path = System.Configuration.ConfigurationManager.AppSettings["app_S4A15"];
            Process sa = new Process();
            try
            {
                sa.StartInfo.FileName = sa_path;
                sa.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
                sa.Start();
                sa.WaitForExit();
                sa.Close();
                GC.Collect();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
    }
}
